export default {
  data() {
    return {
      form: {},
      title: null,
      visible: false, //是否弹出
      loading: false,
      lcol: { xs: { span: 24 }, sm: { span: 5 } },
      wcol: { xs: { span: 24 }, sm: { span: 17 } }
    }
  },
  methods: {
    // 提交表单
    submit(api, data) {
      if (!api) return
      const { $message } = this
      this.loading = true
      api(data)
        .then(res => {
          $message.success('保存成功')
          this.$emit('success', res) //保存成功事件
          this.reset() //重置表单
          this.form = {}
          this.title = null
          this.visible = false
        })
        .catch(err => {
          $message.error(err)
        })
        .finally(() => {
          this.loading = false
        })
    },
    // 重置表单
    reset() {
      if (this.$refs.sjhtform) {
        this.$refs.sjhtform.resetFields()
      }
    }
  }
}
